#include <iostream>

using std::cout;
using std::endl;


class Base
{
public:
    Base()
    //: _base(0)
    {   cout << "Base()" << endl;}

    Base(long base)
    : _base(base)
    {   
        cout << "Base(long)" << endl;
    }

    ~Base() {   cout << "~Base()" << endl;  }
    
    void print() const
    {   cout << "Base::_base:" << _base << endl;    }
private:
    long _base;
};

class Derived
: public Base
{
public:
    Derived(long base, long derived)
    : Base(base)//基类构造函数能够调用是因为该构造函数是public的
    , _derived(derived)
    {   cout << "Derived(long,long)" << endl;}

    ~Derived() {    cout << "~Derived()" << endl;}

    void display() const
    {
        cout << "_derived:" << _derived << endl;
    }

private:
    long _derived;
};

int main()
{
    Base base(1);
    base.print();
    cout << endl;

    Derived d1(20, 100);
    d1.display();

    base = d1;//赋值运算
    //const Base & rhs = d1;//ok
    //Base& operator=(const Base&);
    base.operator=(d1);
    base.print();
    cout << endl;

    //可以用一个派生类对象赋值给基类对象
    Base base2 = d1;
    //Base(const Base&);
    
    //Derived(const Derived &)
    Derived d2 = base;//error


    return 0;
}

